package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.CopyrightQueryDto;
import com.group.eams.pojo.entity.Copyright;
import com.group.eams.pojo.vo.CopyrightBasicVo;
import com.group.eams.pojo.vo.CopyrightListVo;
import com.group.eams.service.CopyrightService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 无形资产(著作权登记表)(Copyright)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/copyright")
public class CopyrightController  {
    /**
     * 服务对象
     */
    @Autowired
    private CopyrightService copyrightService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public Result findById(@RequestParam Long id){
        Copyright copyright = copyrightService.getById(id);
        return Result.buildSuccess(copyright);
    }

    /**
     * 通过id查询基础数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/findBasicById",method = RequestMethod.GET)
    public Result findBasicById(@RequestParam Long id){
        CopyrightBasicVo copyrightBasicVo = copyrightService.findBasicById(id);
        return Result.buildSuccess(copyrightBasicVo);
    }
    /**
     * 分页查询
     *
     * @param copyrightQueryDto 查询条件
     * @return 集合
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(CopyrightQueryDto copyrightQueryDto){
        Page<CopyrightListVo> page = copyrightService.findByQueryDto(copyrightQueryDto);
        return Result.buildSuccess(page.getTotal(),page.getRecords());
    }

    /**
     * 查询所有数据
     *
     * @return 集合
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result findAll(){
        List<Copyright> copyrightList = copyrightService.list();
        return Result.buildSuccess(copyrightList);
    }

    /**
     * 添加数据
     *
     * @param copyright 添加数据
     * @return 添加是否成功
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody Copyright copyright){
        boolean result = copyrightService.save(copyright);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量添加数据
     *
     * @param copyrightList 批量添加数据
     * @return 添加是否成功
     */
    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    public Result addBatch(@RequestBody List<Copyright> copyrightList){
        boolean result = copyrightService.saveBatch(copyrightList);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改数据
     *
     * @param copyright 修改数据
     * @return 修改是否成功
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody Copyright copyright){
        boolean  result = copyrightService.updateById(copyright);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量修改数据
     *
     * @param copyrightList 批量修改数据
     * @return 修改是否成功
     */
    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    public Result updateBatch(@RequestBody List<Copyright> copyrightList){
        boolean result = copyrightService.updateBatchById(copyrightList);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result delete(@RequestParam Long id){
        boolean result = copyrightService.removeById(id);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量删除数据
     *
     * @param batchDeleteDto 批量删除信息
     * @return 删除结果
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    public Result deleteBatch(@RequestBody BatchDeleteDto batchDeleteDto){
        boolean result = copyrightService.removeByIds(batchDeleteDto.getIds());
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    
}

